
import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { ClassService } from './class.service';
import { CreateClassDto, BaseClassDto, UpdateClassDto, QueryClassDto, ListClassDto } from './dto/class.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from 'src/module/system/user/user.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';
import { Operlog } from 'src/common/decorators/operlog.decorator';
import { BusinessType } from 'src/common/constant/business.constant';

@ApiTags('班级')
@Controller('edutation/class')
export class ClassController {
  constructor(private readonly classService: ClassService) {}
  @ApiOperation({ summary: '班级-创建',  })
  @ApiDataResponse(BaseClassDto)
  @RequirePermission('edutation:class:add')
  @Post()
  @RepeatSubmit()
  @Operlog({ businessType: BusinessType.INSERT })
  create(@Body() body: CreateClassDto,@UserTool() { injectCreate }: UserToolType) {
    return this.classService.create(injectCreate(body));
  }


  @ApiOperation({ summary: '班级-列表',  })
  @ApiDataResponse(ListClassDto, true, true)
  @RequirePermission('edutation:class:list')
  @Get('list')
  findAll(@Query() query: QueryClassDto) {
    return this.classService.findAll(query);
  }


  @ApiOperation({  summary: '班级-详情',    })
  @ApiDataResponse(BaseClassDto)
  @RequirePermission('edutation:class:query')
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.classService.findOne(+id);
  }


  @ApiOperation({ summary: '班级-修改',  })
  @ApiDataResponse()
  @RequirePermission('edutation:class:edit')
  @Put()
  @RepeatSubmit()
  @Operlog({ businessType: BusinessType.UPDATE })
  update(@Body() body: UpdateClassDto,@UserTool() { injectUpdate }: UserToolType) {
    return this.classService.update(injectUpdate(body));
  }


  @ApiOperation({  summary: '班级-删除', })
  @ApiDataResponse()
  @RequirePermission('edutation:class:remove')
  @Delete(':ids')
  @Operlog({ businessType: BusinessType.DELETE })
  remove(@Param('ids') ids: string) {
    const classIdList = ids.split(',').map((id) => +id);
    return this.classService.remove(classIdList);
  }
}
